//plugin bootstrap minus and plus
//http://jsfiddle.net/laelitenetwork/puJ6G/
$('.btn-number').click(function(e){
    e.preventDefault();
    
    fieldName = $(this).attr('data-field');
    type      = $(this).attr('data-type');
    var input = $("input[name='"+fieldName+"']");
    var currentVal = parseInt(input.val());
    if (!isNaN(currentVal)) {
        if(type == 'minus') {
            
            if(currentVal > input.attr('min')) {
                input.val(currentVal - 1).change();
            } 
            if(parseInt(input.val()) == input.attr('min')) {
                $(this).attr('disabled', true);
            }

        } else if(type == 'plus') {

            if(currentVal < input.attr('max')) {
                input.val(currentVal + 1).change();
            }
            if(parseInt(input.val()) == input.attr('max')) {
                $(this).attr('disabled', true);
            }

        }
    } else {
        input.val(0);
    }
});
$('.input-number').focusin(function(){
   $(this).data('oldValue', $(this).val());
});
$('.input-number').change(function() {
    
    minValue =  parseInt($(this).attr('min'));
    maxValue =  parseInt($(this).attr('max'));
    valueCurrent = parseInt($(this).val());
    
    name = $(this).attr('name');
    if(valueCurrent >= minValue) {
        $(".btn-number[data-type='minus'][data-field='"+name+"']").removeAttr('disabled')
    } else {
        alert('Sorry, the minimum value was reached');
        $(this).val($(this).data('oldValue'));
    }
    if(valueCurrent <= maxValue) {
        $(".btn-number[data-type='plus'][data-field='"+name+"']").removeAttr('disabled')
    } else {
        alert('Sorry, the maximum value was reached');
        $(this).val($(this).data('oldValue'));
    }
    
    
});
$(".input-number").keydown(function (e) {
        // Allow: backspace, delete, tab, escape, enter and .
        if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 190]) !== -1 ||
             // Allow: Ctrl+A
            (e.keyCode == 65 && e.ctrlKey === true) || 
             // Allow: home, end, left, right
            (e.keyCode >= 35 && e.keyCode <= 39)) {
                 // let it happen, don't do anything
                 return;
        }
        // Ensure that it is a number and stop the keypress
        if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
            e.preventDefault();
        }
    });




	
	  /******************************************
	*SCRIPT GENERE PAR LE GENERATEUR DE SCRIPT D'ASTUFORUM ( http://astuforum.free.fr)  
	* Snow Effect Script- By Altan d.o.o. (http://www.altan.hr/snow/index.html)
	* Visit Dynamic Drive DHTML code library (http://www.dynamicdrive.com/) for full source code
	* Traduction fran�aise par Prof TNJ
	******************************************/
	// Indiquer l'URL de l'image du flocon :
	var urlflocon="./img/coin.png"
	// Ecrire le nombre de flocons :
	var nombreflocons = 10;
	// Indiquer si la neige doit dispara�tre apr�s x secondes (0=jamais) :
	var cacherflocons = 50;
	// Indiquer si la neige doit �tre vue sur la fen�tre ou toute la page avant de dispara�tre ("windowheight"=la fen�tre, "pageheight"=toute la page)
	var voirflocons = "pageheight";
	/////////// FIN DE LA PARTIE CONFIGURATION //////////////////////////////////
	var ie4up = (document.all) ? 1 : 0;
	var ns6up = (document.getElementById&&!document.all) ? 1 : 0;
	function testIEcompatible(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	}
	var dx, xp, yp; // Variables de coordonn�es et de position
	var am, stx, sty; // Variables d'amplitude
	var i, doc_width = 1024, doc_height = 768; // Taille de l'�cran
	if (ns6up) {
	doc_width = self.innerWidth;
	doc_height = self.innerHeight;
	} else if (ie4up) {
	doc_width = testIEcompatible().clientWidth;
	doc_height = testIEcompatible().clientHeight;
	}
	dx = new Array();
	xp = new Array();
	yp = new Array();
	am = new Array();
	stx = new Array();
	sty = new Array();
	for (i = 0; i < nombreflocons; ++ i) {
	dx[i] = 0; // Variables de coordonn�es
	xp[i] = Math.random()*(doc_width-50); // Variables de position
	yp[i] = Math.random()*doc_height;
	am[i] = Math.random()*20; // Variables d'amplitude
	stx[i] = 0.02 + Math.random()/10; // Variables de pas?
	sty[i] = 0.7 + Math.random(); // Variables de pas
	if (ie4up||ns6up) {
	if (i == 0) {
	document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;\"><img src='"+urlflocon+"' border=\"0\"><\/div>");
	} else {
	document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;\"><img src='"+urlflocon+"' border=\"0\"><\/div>");
	}
	}
	}
	function neigeIE_NS6() { // IE et NS6 : fonctions principales d'animation
	doc_width = ns6up?window.innerWidth-10 : testIEcompatible().clientWidth-10;
	doc_height=(window.innerHeight && voirflocons=="windowheight")? window.innerHeight : (ie4up && voirflocons=="windowheight")? testIEcompatible().clientHeight : (ie4up && !window.opera && voirflocons=="pageheight")? testIEcompatible().scrollHeight : testIEcompatible().offsetHeight;
	for (i = 0; i < nombreflocons; ++ i) { // d�placement pour chaque point ("dot")
	yp[i] += sty[i];
	if (yp[i] > doc_height-50) {
	xp[i] = Math.random()*(doc_width-am[i]-30);
	yp[i] = 0;
	stx[i] = 0.02 + Math.random()/10;
	sty[i] = 0.7 + Math.random();
	}
	dx[i] += stx[i];
	document.getElementById("dot"+i).style.top=yp[i]+"px";
	document.getElementById("dot"+i).style.left=xp[i] + am[i]*Math.sin(dx[i])+"px";
	}
	snowtimer=setTimeout("neigeIE_NS6()", 10);
	}
	function cacherneige(){
	if (window.snowtimer) clearTimeout(snowtimer)
	for (i=0; i<nombreflocons; i++) document.getElementById("dot"+i).style.visibility="hidden"
	}
	if (ie4up||ns6up){
	neigeIE_NS6();
	if (cacherflocons>0)
	setTimeout("cacherneige()", cacherflocons*1000)
	}

